<template>
	<view class="main">
		<!-- 顶部 -->
		<view class="mian-top">
			<text class="mian-top-title" >工作日期</text>
			<text class="mian-top-title" >工作时长</text>
			<text class="mian-top-title">工作内容</text>
			<text class="mian-top-title" >工作律师</text>
		</view>

		<view style="margin-top: 80rpx;" :style="{marginBottom:marginBottom}">
			<view v-for="(item,index) in dataList" :key="index"  
				@click="clickTap(item)" @longpress="longpress(item)">
				<view class="data-item">
					<view class="mian-top-content">
						
						<text style="margin-left: 14rpx;">{{item.workDate}}</text>
					</view>
					<view class="mian-top-content">
						
						<text style="margin-left: 30rpx;">{{item.workDuration}}</text>
					</view>
					<view class="mian-top-content">
						
						<text style="margin-left: 40rpx;">{{item.workContent}}</text>
					</view>
					<view class="mian-top-content">
						
						<text style="margin-left: 48rpx;">{{item.lawyerss}}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 底部 -->
		<view class="view-bottom">
			<view class="view-bottom-s">
				<view class="view-bottom-b" @click="addIt">
					增加
				</view>
			</view>
			<!-- <view style="height: 68rpx;background: #ffffff;" v-if="needAdapt"> -->
				<!-- 苹果x及以上的安全距离 -->
			<!-- </view> -->

		</view>
		
		<view class="zhezhao" v-if="isShowTips">
			<view class="zhezhao-view-bottom">
				<view class="zhezhao-view-bottom-s" @click="clickTap(1)">
					编辑
				</view>
				<view class="zhezhao-view-bottom-s" @click="clickTap(2)">
					删除
				</view>
				<view class="zhezhao-view-bottom-s" @click="clickTap(3)">
					取消
				</view>
			</view>
		</view>
		
		

	</view>
</template>

<script>
	let app = ''
	export default {
		data() {
			return {
				role:'',
				roleUrl:'',
				caseId:'',
				needAdapt: false,
				marginBottom: '',
				windowHeight: 0,
				dataList: [],
				
				isShowTips:false,
				
				item:null
				

			}
		},
		onLoad(options) {
			app = getApp()
			var _this = this
			_this.caseId = options.caseId
			// console.log(_this.chooseList)
			_this.needAdapt = app.globalData.needAdapt && app.globalData.isIPhone
			_this.role = app.globalData.role
			_this.roleUrl =  _this.$roleUrl({tab:_this.role})
			if (_this.needAdapt) {
				_this.marginBottom = 180 + 'rpx'
				_this.windowHeight = (app.globalData.windowHeight - 128) * 2 + 'rpx'
			} else {
				_this.marginBottom = 110 + "rpx"
				_this.windowHeight = (app.globalData.windowHeight - 96) * 2 + 'rpx'
			}
			
		},
		onShow() {
			this.getList()

		},
		mounted() {

		},
		methods: {
			
			/**
			 * 查看列表
			 */
			async getList(){
				let _this = this
				let data={
					page:1,
					size:10000,
					caseId:_this.caseId
				}
	
				uni.showLoading({
					title:'正在加载数据...'
				})
				const res = await _this.$myRequest({
					url: `/${_this.roleUrl}/caseWorkLog/list`,
					data:data,
					method:'POST',//默认是GET
				})
				uni.hideLoading()
				console.log('列表',res)
				if(res.data.code==200){
					let list = res.data.data.list
					for (var i = 0; i < list.length; i++) {
						
						let date = list[i]['workDate']
						if(date!=null && date!=undefined && data!=''){
							date =  date.substring(0,10)
						}
						list[i]['workDate'] = date
						
						let lawyersList = list[i]['lawyers']
						console.log('lawyersList',lawyersList)
						if(lawyersList!=null && lawyersList!=undefined){
							let lawyers = ''
							for (var j = 0; j < lawyersList.length; j++) {
								lawyers = lawyers+lawyersList[j]['account']['realName']+'、'
							}
							if(lawyers.indexOf('、')>-1){
								lawyers = lawyers.substring(0,lawyers.length-1)
							}
						
							list[i]['lawyerss'] = lawyers
						}else{
							list[i]['lawyerss'] = ''
						}
						
					
						
					}
					_this.dataList = list
				}
			},
			
			/**
			 * 长按
			 */
			longpress(val){
				console.log('长按',val)
				this.item = val
				this.isShowTips = true
			},
			
			/**
			 * 点击
			 */
			clickTap(val){
				this.isShowTips = false
				
				console.log('点击',val)
				if(val==1){
					//编辑
					let item = JSON.stringify(this.item)
					uni.navigateTo({
						url:'addWorkTime?caseId='+this.caseId+'&tag=edit&item='+item
					})
				}else if(val==2){
					//删除
					this.deleteIt()
				}else if(val==3){
					//取消
					this.item = null
					
				}else{
					let item = JSON.stringify(val)
					uni.navigateTo({
						url:'addWorkTime?caseId='+this.caseId+'&tag=edit&item='+item
					})
				}
			},
			
			/**
			 * 新增
			 */
			addIt() {
				uni.navigateTo({
					url:'addWorkTime?caseId='+this.caseId+'&tag=add'
				})

			},
			/**
			 * 删除
			 */
			async deleteIt(){
				let _this = this
				uni.showLoading({
					title:'正在删除...'
				})
				const res = await _this.$myRequest({
					url: `/${_this.roleUrl}/caseWorkLog`,
					data: {
						ids:_this.item.id
					},
					method: 'DELETE', //默认是GET
				})
				uni.hideLoading()
				if(res.data.code==200){
					uni.showToast({
						title:'删除成功!',
						icon:"success"
					})
					_this.dataList = []
					_this.getList()
				}
			},
		}
	}
</script>

<style>
	page {
		background-color: #ffffff;
	}
</style>

<style scoped lang="scss">
	.main {}

	.mian-top {
		position: fixed;
		top: 0;
		width: 100%;
		height: 80rpx;
		z-index: 9999;
		background: #E8F7FB;
		display: flex;
		align-items: center;
	}

	.view-bottom {
		position: fixed;
		width: 100%;
		bottom: 0;
		background-color: #ffffff;
		padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部
	}

	.view-bottom-s {
		height: 108rpx;
		display: flex;
		align-items: center;
	}

	.view-bottom-b {
		width: 686rpx;
		height: 88rpx;
		background: #2DA9C5;
		border-radius: 58rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 36rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #E8F7FB;
		line-height: 50rpx;
		margin-left: 32rpx;
	}

	.mian-top-title {
		width: 25%;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
		text-align: center;
	}

	.data-item {
		// height: 88rpx;
		display: flex;
		padding-top: 16rpx;
		padding-bottom: 16rpx;
		// align-items: center;
		margin-left: 18rpx;
		margin-right: 18rpx;
		border-bottom: 1rpx #eeeeee solid;
	}
	.mian-top-content{
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
		width: 25%;
	}
	
	
	.zhezhao {
		width: 100%;
		height: 100vh;
		background: rgba(0, 0, 0, 0.4);
		z-index: 9999;
		position: fixed;
		left: 0;
		top: 0;
		overflow: scroll;	
		// padding-top: 10vh;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.zhezhao-view-bottom{
		position: fixed;
		width: 100%;
		bottom: 0;
		background-color: #ffffff;
		border-top-right-radius: 16rpx;
		border-top-left-radius: 16rpx;
		padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部
	}
	.zhezhao-view-bottom-s{
		height:88rpx;
		border-bottom: 1rpx #eeeeee solid;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
	
	}
	
</style>
